﻿#ifndef GAMECONTROL_H
#define GAMECONTROL_H

#include <QObject>
#include "robot.h"
#include "userplayer.h"
struct BetRecord
{
    //结构体就相当于类，定义一个构造函数进行初始化
    BetRecord()
    {
        reset();
    }
    void reset()
    {
        player=nullptr;
        point=0;
        times=0;
    }
    Player* player;
    int point;
    int times;//记录第几次叫地主
};

class GameControl : public QObject
{
    Q_OBJECT
public:
    explicit GameControl(QObject *parent = nullptr);
    enum GameStatus{
        DispatchCard,
        CallingLord,
        PlayingHnad
    };
    enum PlayerStatus{
        ThinkingForCallLord,
        ThinkingForPlayHand,
        winning
    };
    //玩家初始化
    void playerInit();
    //获取玩家实例
    Robot* getLeftRobot();
    Robot* getRightRobot();
    UserPlayer* getUserPlayer();

    //获取设置当前玩家
    void setCurPlayer(Player* player);
    Player* getCurPlayer();

    //得到出牌玩家和打出的未处理的牌
    Player* getPendPlayer();
    Cards getPendCards();

    //初始化所有牌
    void initAllCards();

    //发一张牌
    Card takeOneCard();

    //剩下的3张牌
    Cards getSurplusCards();

    //重置卡牌
    void resetCardData();
    //准备叫地主
    void startLordCard();
    //成为地主
    void becomeLord(Player* player,int bet);
    //清空分数
    void clearPlayerScre();
    void onGrabBet(Player* player,int point);
    int getPlayerMaxBet();
    //处理出牌
    void onPlayhand(Player* player,Cards cards);
    //没有被管住的牌的玩家
    Player* m_pendPlayer;
signals:
    void playerStatusChanged(Player* palyer,PlayerStatus status);//通知主窗口玩家状态发生变化
    void notifyGrabLordBet(Player* player,int point,bool flag);//flag标志是否是第一个抢地主的玩家
    void gameStatusChanged(GameStatus status);
    //出牌信号给主界面
    void notifyPlayhand(Player* player,Cards &cards);
    //出牌信号给玩家
    void pendingInfo(Player* player,Cards &cards);
private:
    Robot* m_robotLeft;
    Robot* m_roborRight;
    UserPlayer* m_userPlayer;
    //当前玩家
    Player* m_curPlayer;

    //出牌玩家打出的牌
    Cards m_pendCards;
    Cards m_allCards;
    struct BetRecord m_betRecord;
    int m_curBet;//当前底分

};

#endif // GAMECONTROL_H
